package com.lianjia.sh.tools.msg.v1.sender.impl;

import com.dooioo.se.client.RestClient;
import com.dooioo.se.client.RestClientException;
import com.lianjia.sh.tools.msg.v1.model.FullWebMsg;
import com.lianjia.sh.tools.msg.v1.model.Msg;
import com.lianjia.sh.tools.msg.v1.sender.FullWebSender;
import org.springframework.http.HttpMethod;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangsp1 on 16/6/27.
 */
public class FullWebSenderImpl implements FullWebSender {
    String fullWebMsgUrl;

    @Override
    public boolean send(FullWebMsg fullWebMsg) {
        Map<String,Object> params = new HashMap<>();
        params.put("content", fullWebMsg.getContent());
        params.put("empNo", fullWebMsg.getEmpNo());
        params.put("source", fullWebMsg.getSource());
        params.put("sendTime", fullWebMsg.getSendTime());
        params.put("linkUrl", fullWebMsg.getLinkUrl());
        params.put("type", fullWebMsg.getType());
        try {
            RestClient.exchange(fullWebMsgUrl, HttpMethod.POST, String.class, params);
        } catch (RestClientException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean send(Msg msg) {
        return send((FullWebMsg) msg);
    }

    @Override
    public boolean isMatch(Msg msg) {
        return msg != null && msg instanceof FullWebMsg;
    }

    @Override
    public String getFullWebMsgUrl() {
        return null;
    }

    @Override
    public void setFullWebMsgUrl(String fullWebMsgUrl) {

    }
}
